package games.labirynth;

import hardware.Display2D;

public class Maze {

	private short [] mazeData=null;

public static final int POSITION_ILLEGAL 		=	-1;	
public static final int POSITION_EMPTY 			=	0;
public static final int POSITION_SMALL_WALL 	=	1;
public static final int POSITION_LARGE_WALL 	=	2;
public static final int POSITION_DESTINATION 	=	3;

public void set(short[] newMaze)
{
	mazeData=newMaze;
}

public void draw()
{
	int counter;
	int xCounter;
	int data;
	int wall;
	if (mazeData==null)
		return;

	for (counter=0;counter<mazeData.length;counter++)
		{
		data=mazeData[counter];
		for (xCounter=0;xCounter<Display2D.getColumnCount();xCounter++)
			{
			wall=data&0x3;
			data>>=2;
			
			switch(wall)
			{
			case POSITION_EMPTY:
				Display2D.setPixel(xCounter,counter,(short) 0x0);				
				break;

			case POSITION_SMALL_WALL:
				Display2D.setPixel(xCounter,counter, (short)0x555);				
				break;
				
			case POSITION_LARGE_WALL:
				Display2D.setPixel(xCounter,counter, (short)0xfff);
				break;

			case POSITION_DESTINATION:
				Display2D.setPixel(xCounter,counter, (short)0xf00);
				break;

			}
		
			}

		
		
		}
	
	
}

public int checkPosition(int xPos, int yPos)
{
int value;
	
	if (yPos>=mazeData.length)
		return(POSITION_ILLEGAL);
	
	value=(mazeData[yPos]>>(2*xPos))&0x3;
	
	
	return(value);
}

}